package com.sdweizan.sdk.bytedance.error;

public class BdErrorException extends Exception {
  private static final long serialVersionUID = 5826243875244514008L;
  private final BdError error;

  private static final String DEFAULT_ERROR_CODE = "-1";

  public BdErrorException(String message) {
    this(BdError.builder().errorCode(DEFAULT_ERROR_CODE).errorMsg(message).build());
  }

  public BdErrorException(BdError error) {
    super(error.toString());
    this.error = error;
  }

  public BdErrorException(BdError error, Throwable cause) {
    super(error.toString(), cause);
    this.error = error;
  }

  public BdErrorException(Throwable cause) {
    super(cause.getMessage(), cause);
    error =
        BdError.builder().errorCode(DEFAULT_ERROR_CODE).errorMsg(cause.getMessage()).build();
  }

  public BdError getError() {
    return error;
  }
}
